package view;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;

import resources.ResourceProvider;

import model.EmailImp;

/**
 * This is a Class to represent JTable to display the Emails
 */
public class MailTable extends JTable implements MouseListener
{
    
    private static final long serialVersionUID = 1393657622996074905L;
    
    private MailDisplayArea mailDisplayArea;
    
   /**
    * Constructor for class MailTable that will display the mail display area used.
    *  
    * @param mailDisplayArea
    * @param model
    */
    public MailTable(MailDisplayArea mailDisplayArea, AbstractTableModel model)
    {
        super(model);
        this.mailDisplayArea = mailDisplayArea;
        this.addMouseListener(this);
    }

    
    
  /*
   * (non-Javadoc)
   * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
   */
    public void mouseClicked(MouseEvent e)
    {
        if ((e.getButton() == MouseEvent.BUTTON1) && (e.getClickCount() == 2)) 
        {
            JTable target = (JTable)e.getSource();
            int row = target.getSelectedRow();
            EmailImp email = ((EmailTableModel)this.getModel()).getEmailAssociatedToRow(row);
            boolean isDraft = false;
            if(email.getPersistencePath().contains(ResourceProvider.DRAFT))
            {
                isDraft = true; 
            }
            this.mailDisplayArea.displaySelectedEmail(email,isDraft);
        }
    }

    
    public void mousePressed(MouseEvent e)
    {
        
    }

    
    public void mouseReleased(MouseEvent e)
    {
        
    }

    
    public void mouseEntered(MouseEvent e)
    {
        
    }

    
    public void mouseExited(MouseEvent e)
    {
        
    }
}
